package com.yuyou.fn.provider.impl;

import com.google.common.collect.Collections2;
import com.yuyou.fn.api.SuggestCourseClassService;
import com.yuyou.fn.api.dto.OuterCourseClassDto;
import com.yuyou.fn.api.dto.SuggestResultDto;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.portal.entity.OuterCourseClass;
import com.yuyou.fn.portal.service.ISuggestionService;
import com.yuyou.fn.portal.vo.SuggestResultVo;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ExposeSuggestCourseClassServiceImpl implements SuggestCourseClassService {

    @Resource
    private ISuggestionService suggestionService;

    @Override
    public SuggestResultDto suggestContinueClass(Long studentId) {
        SuggestResultVo suggestResultVo = suggestionService.suggestContinueClass(studentId);
        SuggestResultDto suggestResultDto = new SuggestResultDto() ;
        if(suggestResultVo != null && suggestResultVo.getBaseSuggests() != null ){
            suggestResultDto.setBaseSuggests(Collections2.transform(suggestResultVo.getBaseSuggests(),this::toCourseClassDto ));
        }
        if(suggestResultVo != null && suggestResultVo.getMoreSuggests() != null ){
            suggestResultDto.setMoreSuggests(Collections2.transform(suggestResultVo.getMoreSuggests(),this::toCourseClassDto ));
        }
        return suggestResultDto;
    }

    @Override
    public Collection<OuterCourseClassDto> suggestCourseClass(Long areaTeamId , Long userId) {
        List<OuterCourseClass> outerCourseClasses = suggestionService.suggestCourseClass(areaTeamId, null, null, userId);
        if(outerCourseClasses == null ){
            return Collections.EMPTY_LIST;
        }
        return Collections2.transform(outerCourseClasses,(o)->{
            OuterCourseClassDto  outerCourseClassDto = new OuterCourseClassDto() ;
            BeanUtils.copyProperties(outerCourseClassDto,o);
            return outerCourseClassDto ;
        });
    }

    private OuterCourseClassDto toCourseClassDto(OuterCourseClass c) {
        OuterCourseClassDto outerCourseClassDto = new OuterCourseClassDto();
        BeanUtils.copyProperties(outerCourseClassDto, c  );
        return outerCourseClassDto;
    }
}
